#include "main.h"
bool gb_heattubedeal;
bool gb_FirstModeStart;   	//各模式首次开始工作
bool gb_skeeptemper;
bool gb_bkeeptemper;
u8   gu8_zerodelay;
u8   gu8_zerodefault;//零点失效
u8   gu8_BakeDlyCnt;
u8   gu8_steamDlyCnt;

u8   gu8_DisinfWorkStatus;

bool gb_twoboxwork;
bool cg_heat_f;
u16  gu16_allpowercnt;

u8   gu8_smbtmheat;
u8   gu8_bktopheat;

void top_heater_power_ctr(void)
{//过零检测没坏的情况下 period = 10ms
    static u8 pcycle_ct = 0;
    static u8 old_p = 0;
    u8 pow = 0;
    pow = ht_Itop_out.perc;
    if(gb_TestFlag)
        return;
    if(gb_heattubedeal)
    {
        if (pcycle_ct < 99)
            pcycle_ct++;
        else
            pcycle_ct = 0;
    }


    if (old_p != pow)
    {
        if ((pow == 100) || (pow == 0))
        {
            old_p = pow; //pcycle_ct = 0;
        }
    }

    if (pcycle_ct == 0)
        old_p = pow;

    if (pcycle_ct < old_p)
    {
        PIN_HT_TOP = 1;        
    }
    else
    {
        PIN_HT_TOP = 0;           
    }
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void outtop_heater_power_ctr(void)
{//过零检测没坏的情况下 period = 10ms
    static u8 pcycle_ct = 0;
    static u8 old_p = 0;
    u8 pow = 0;
    pow = ht_Otop_out.perc;
    if(gb_TestFlag)
        return;
    if(gb_heattubedeal)
    {
        if (pcycle_ct < 99)
            pcycle_ct++;
        else
            pcycle_ct = 0;
    }


    if (old_p != pow)
    {
        if ((pow == 100) || (pow == 0))
        {
            old_p = pow;// pcycle_ct = 0;
        }
    }

    if (pcycle_ct == 0)
        old_p = pow;

    if (pcycle_ct < (100 - old_p))
    {
       
        PIN_HT_OTOP = 0;         
    }
    else
    {

        PIN_HT_OTOP = 1;               
    }
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void bomi_heater_power_ctr(void)
{//过零检测没坏的情况下 period = 10ms
    static u8 pcycle_ct = 0;
    static u8 old_p = 0;
    u8 pow = 0;
    pow = ht_Ibom_out.perc;

    if(gb_TestFlag)
        return;
    if(gb_heattubedeal)
    {
        if (pcycle_ct < 99)
            pcycle_ct++;
        else
            pcycle_ct = 0;
    }


    if (old_p != pow)
    {
        if ((pow == 100) || (pow == 0))
        {
            old_p = pow;// pcycle_ct = 0;
        }
    }

    if (pcycle_ct == 0)
        old_p = pow;

    if (pcycle_ct < old_p)
    {
        PIN_HT_BOMI = 1;
    }
    else
    {
        PIN_HT_BOMI = 0;
    }
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void bomo_heater_power_ctr(void)
{//过零检测没坏的情况下 period = 10ms
    static u8 pcycle_ct = 0;
    static u8 old_p = 0;
    u8 pow = 0;
    pow = ht_Obom_out.perc;
    if(gb_TestFlag)
        return;
    if(gb_heattubedeal)
    {
        if (pcycle_ct < 99)
            pcycle_ct++;
        else
            pcycle_ct = 0;
    }


    if (old_p != pow)
    {
        if ((pow == 100) || (pow == 0))
        {
             old_p = pow;//pcycle_ct = 0;
        }
    }

    if (pcycle_ct == 0)
        old_p = pow;

    if (pcycle_ct < (100 - old_p))
    {
        PIN_HT_BOMO = 0;                    
    }
    else
    {
        PIN_HT_BOMO = 1;                   
    }
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void left_heater_power_ctr(void)
{//过零检测没坏的情况下 period = 10ms
    static u8 pcycle_ct = 0;
    static u8 old_p = 0;
    u8 pow = 0;
    pow = ht_Lbom_out.perc;

    if(gb_TestFlag)
        return;
    if(gb_heattubedeal)
    {
        if (pcycle_ct < 99)
            pcycle_ct++;
        else
            pcycle_ct = 0;
    }


    if (old_p != pow)
    {
        if ((pow == 100) || (pow == 0))
        {
            old_p = pow;// pcycle_ct = 0;
        }
    }

    if (pcycle_ct == 0)
        old_p = pow;

    if (pcycle_ct < old_p)
    {

        PIN_HT_LEFT = 1;            
    }
    else
    {    
        PIN_HT_LEFT = 0;              
    }
}
void pre_heater_power_ctr(void)
{//过零检测没坏的情况下 period = 10ms
    static u8 pcycle_ct = 0;
    static u8 old_p = 0;
    u8 pow = 0;
    pow = ht_pre_out.perc;

    if(gb_TestFlag)
        return;
    if(gb_heattubedeal)
    {
        if (pcycle_ct < 99)
            pcycle_ct++;
        else
            pcycle_ct = 0;
    }


    if (old_p != pow)
    {
        if ((pow == 100) || (pow == 0))
        {
            old_p = pow;// pcycle_ct = 0;
        }
    }

    if (pcycle_ct == 0)
        old_p = pow;

    if (pcycle_ct < old_p)
    {
        PIN_HT_PRE = 1;            
    }
    else
    {      
        PIN_HT_PRE = 0;              
    }
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void clear_steam(void)
{
    ht_Ibom_out.perc = 0;
    ht_Otop_out.perc = 0;
    ht_Obom_out.perc = 0;
    ht_Itop_out.perc = 0;

}
void clear_bake(void)
{ 
    ht_Lbom_out.perc = 0;
    
}

bool check_ht_work(void) //
{
    if (ht_Ibom_out.perc)   return 1;
    if (ht_Itop_out.perc)   return 1;
    if (ht_Obom_out.perc)   return 1;
    if (ht_Otop_out.perc)   return 1;
    if (ht_Lbom_out.perc)   return 1;
    return 0;
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void steampower_allot(void)
{
    static u16 changcnt = 0;//升温到保温计时
    static u8 work_dly = 0;//干烧加水增加大功率工作时间
    static u16 keepcnt = 0;//高原判断计时
    static bool gb_hlevel = 0; //高原标志 
    static u16 pretemper = 0; //上一次温度
    static u16 worktimecnt = 0; //工作计时，不工作清零包括暂停

    static u8 cg_dly = 0;
    static u8 power = 0;
    static u8 presoft_step = 0;
    static u8 dscal_heat_f = 0;
    static u8 cyc_cnt = 0;
    u8 temper = 0;
    u8 powerlow = 0;
    if((gu8_SystemBeginTime > 2) )
        return; 
    if(steamCtrl.state == STA_WORK)
        boxlock_f = 1;
    else
        boxlock_f = 0;
    if(gb_washboxwork)
    {
        if(gu8_AddWaterTime1 == 1)
        {
            gu8_draintime = 30;
        }
		
		if(gu8_AddWaterTime1 == 0)
		{
			if(gu8_draintime == 0)
			{
				gb_washboxwork = 0;
				gu8_AddWaterTime1 = 40;
			}
		}
    }
    if(gb_stubecheck ||gb_btubecheck)
    {
        if(gb_stcheckdly||(gb_stubecheck == 0))
            clear_steam();
        return;
    }
    if(gs_tofaceSTubeError)
    {
        clear_steam();
        boxlock_f = 0;
        changcnt = 0;
        work_dly = 0;
        keepcnt = 0;
        return;
    }
    if (steamCtrl.state == STA_WORK)
    {//工作状态         
        if(((gb_DryFireFlag||(waterbox.sta == BOX_OPEN))&& ((steamPara.menu != WORK_CHUJUN)||((steamPara.menu == WORK_CHUJUN)&&(gu8_DisinfWorkStatus <= 1))))
        ||((door.sta == DOOR_OPEN)&&(steamPara.menu != WORK_SOFT))||gb_washboxwork)
        {
			clear_steam();
            changcnt = 0;
            work_dly = 0;
            keepcnt = 0;
            gu8_smbtmheat = 0;
            pretemper = 0;
            return;
        }
        switch(steamPara.menu)
        {
            case WORK_STEAMPURE:
            case WORK_FISH:              // 鱼类模式2
            case WORK_VEGTAB:            // 蔬菜模式3
            case WORK_EGG:          	 // 蛋类模式4
            case WORK_NOODLE:     		 // 面食模式5
            case WORK_SOUP:	             // 煲汤模式6  
            case WORK_WASH:                     
            {
                clear_steam();
                if(system_sec_f) 
                {
                    u16_up(&worktimecnt);
                    u8_dn(&cg_dly);
                }  

                if(steamPara.tempr_set <= 100)
                {                   
                    if(gu8_AddWaterTime1)
                    {
                        ht_Itop_out.perc = 0;
                        ht_Ibom_out.perc = 0;	
                        gu8_smbtmheat = 0;	                        
                        // if(gb_TemptrDown)
                        // {
                        //     ht_Itop_out.perc = 100;                                                         
                        // }
                        if(steamPara.tempr_set >= 95) 
                        {
                            if(worktimecnt <= (10*60))
                                work_dly = 15;  //15
                            else
                                work_dly = 8; 
                        }                                           
                        else if(steamPara.tempr_set >= 90) 
                            work_dly = 8;   
                        else        
                            work_dly = 5;        
                    }
                    else
                    {
                        if(system_sec_f)
                            u8_dn(&work_dly);
                        if(steamPara.tempr_set >= 98)
                            temper = STEAM_PID.u16_itemtemp-1;//2
                        else if(steamPara.tempr_set >= 94)
                            temper = STEAM_PID.u16_itemtemp-3;                            
                        else if(steamPara.tempr_set >= 90)
                            temper = STEAM_PID.u16_itemtemp-4;
                        else if(steamPara.tempr_set >= 80)
                            temper = STEAM_PID.u16_itemtemp-10;
                        else if(steamPara.tempr_set >= 70)
                            temper = STEAM_PID.u16_itemtemp-30;
                        else
                            temper = STEAM_PID.u16_itemtemp-40;  
                        if(gb_skeeptemper == 0)
                        {
                            if((tempr_box.cur > 85)&& (tempr_box.cur <= pretemper+1))
                            {
                                if(system_sec_f)
                                    keepcnt++;
                                if(keepcnt >= 300)
                                {
                                    keepcnt = 0;
                                    gb_hlevel = 1;
                                    gb_skeeptemper = 1;
                                    STEAM_PID.u8_iPriVal = 100;
                                }
                            }
                            else
                            {
                                gb_hlevel = 0;
                                keepcnt = 0;
                                pretemper = tempr_box.cur;
                            }
                        }  
                        else
                        {
                            keepcnt = 0;
                            pretemper = 85;
                        }
                        if(tempr_box.cur <= 85)
                            gb_hlevel = 0;
                        if(steamPara.tempr_set >= 98)
                        {
                            if(gb_skeeptemper == 0)
                            {                           
                                if(tempr_box.cur >= (temper))
                                {
                                    if(system_sec_f)
                                        changcnt++;        
                                    if(changcnt >= 15)
                                    {
                                        changcnt = 0;
                                        gb_skeeptemper = 1;
                                        STEAM_PID.u8_iPriVal = 70;
                                        //STEAM_PID.u8_iPriVal = (STEAM_PID.u8_iPriVal*3)>100?100:(STEAM_PID.u8_iPriVal*3);
                                    }                                 
                                }
                                
                            }
                            else
                            {
                                if(tempr_box.cur <= (temper-8) &&(gb_hlevel == 0))
                                {
                                    changcnt++;
                                    if(changcnt >= 30)
                                    {
                                        changcnt = 0;
                                        gb_skeeptemper = 0;
                                        STEAM_PID.u8_iPriVal = 50;
                                    }                                
                                }
                            }

                            if(gb_skeeptemper == 0)
                            {
                                ht_Itop_out.perc = 100;//STEAM_PID.u8_iPriVal;//100;                               
                                if(gu8_steamDlyCnt == 0)
                                {
                                    if(work_dly)
                                        ht_Ibom_out.perc = 100;
                                    else
                                    {
                                        if(gu16_allpowercnt < STEAM_PID.u8_iPriVal)
                                        {
                                            ht_Ibom_out.perc = 100;
                                        }
                                        else
                                            ht_Ibom_out.perc = 0;                                         
                                    }
                                        
                                }                                   
                                else
                                    ht_Ibom_out.perc = 0;  
                                gu8_smbtmheat = 100;                                
                                gu8_BakeDlyCnt = 3;  
                                cg_heat_f = 0; 
                                cg_dly = 0;                                
                            }
                            else
                            {                                
                                {
                                    if(tempr_box.cur >= (STEAM_PID.u16_itemtemp-1))//-1
                                    {
                                        STEAM_PID.u8_iPriVal = 70;
                                        cg_dly = 15;
                                    }
                                    else
                                    {
                                        if(cg_dly)
                                            STEAM_PID.u8_iPriVal = 70;
                                        else 
                                        {  
                                            if(tempr_box.cur <= (STEAM_PID.u16_itemtemp-5)) 
                                                STEAM_PID.u8_iPriVal = 100;
                                            else                                  
                                                STEAM_PID.u8_iPriVal = 80;
                                        }
                                        
                                    }
                                    power = STEAM_PID.u8_iPriVal;
                                    if(work_dly)
                                        power = 100;   
                                    if((gu16_allpowercnt < power )&& gu16_allpowercnt)//&&(gu8_steamDlyCnt == 0)
                                    {
                                        if(cg_heat_f == 0)
                                        {
                                            ht_Itop_out.perc = 100;
                                            ht_Ibom_out.perc = 0;
                                        }
                                        else        
                                        {                             
                                            ht_Ibom_out.perc = 100;
                                            ht_Itop_out.perc = 0;
                                        }
                                    }
                                    else
                                    {
                                        ht_Itop_out.perc = 0;
                                        ht_Ibom_out.perc = 0;
                                    }
                                    gu8_smbtmheat = 0; 
                                }                           
                            }

                            if(tempr_box.cur <= (STEAM_PID.u16_itemtemp - 40))
                                ht_Otop_out.perc = 100;
                            else if(tempr_box.cur <= (STEAM_PID.u16_itemtemp - 18))//15
                                ht_Otop_out.perc = 60;
                            else if(tempr_box.cur <= (STEAM_PID.u16_itemtemp-10))
                                ht_Otop_out.perc = 40;//40;                                 
                            else if(tempr_box.cur <= (STEAM_PID.u16_itemtemp-5))
                                ht_Otop_out.perc = 30;//40;   
                            else if(tempr_box.cur <= (STEAM_PID.u16_itemtemp-1))
                                ht_Otop_out.perc = 30;//40;
                            else if(tempr_box.cur <= (STEAM_PID.u16_itemtemp+1))
                            {
                                if(worktimecnt <= 20*60)
                                    ht_Otop_out.perc = 25;
                                else
                                    ht_Otop_out.perc = 22;  //18(中心偏高一度，四周偏高3度）//15是偏低的//20  
                            }
                            else if(tempr_box.cur <= (STEAM_PID.u16_itemtemp+2))
                                ht_Otop_out.perc = 15;
                            else 
                                ht_Otop_out.perc = 8;                                                                                                 
                 
                        }
                        else
                        {
                            if(gb_skeeptemper == 0)
                            {                           
                                if(tempr_box.cur >= (temper))
                                {
                                    if(system_sec_f)
                                        changcnt++;                                   
                                    if(changcnt >= 10)
                                    {
                                        changcnt = 0;
                                        gb_skeeptemper = 1;
                                        STEAM_PID.u8_iPriVal = (STEAM_PID.u8_iPriVal*1.5)>100?100:(STEAM_PID.u8_iPriVal*1.5);
                                    }
                                }
                            }
                            else
                            {
                                if(tempr_box.cur <= (temper-8)&&(gb_hlevel ==0))
                                {
                                    changcnt++;
                                    if(changcnt >= 30)
                                    {
                                        changcnt = 0;
                                        gb_skeeptemper = 0;
                                    }                                
                                }
                            }

                            if(gb_skeeptemper == 0)
                            {

                                ht_Itop_out.perc = STEAM_PID.u8_iPriVal;
                                if(gu8_steamDlyCnt == 0)
                                    ht_Ibom_out.perc = STEAM_PID.u8_iPriVal; 
                                else
                                    ht_Ibom_out.perc = 0;  
                                    
                                gu8_smbtmheat = 100;
                                gu8_BakeDlyCnt = 3;  
                                cg_heat_f = 0;  
                                cg_dly = 0;                    
                            }
                            else
                            { 
                                if((power != STEAM_PID.u8_iPriVal))
                                {
                                    if((STEAM_PID.u8_iPriVal > power)&&(cg_dly == 0))
                                    {
                                        power =  STEAM_PID.u8_iPriVal;
                                        cg_dly = 30;
                                    }
                                    else
                                        power = STEAM_PID.u8_iPriVal;
                                }
                                if(work_dly)     
                                    power = 100;  
                                if((gu16_allpowercnt < power)&&gu16_allpowercnt) 
                                {
                                    if(cg_heat_f == 0)
                                    {
                                        ht_Itop_out.perc = 100;
                                        ht_Ibom_out.perc = 0;
                                    }
                                    else
                                    {                              
                                        ht_Ibom_out.perc = 100; 
                                        ht_Itop_out.perc = 0;
                                    }
                                }  
                                else
                                {
                                    ht_Itop_out.perc = 0;
                                    ht_Ibom_out.perc = 0;
                                } 
                                gu8_smbtmheat = 0;                            
                            }                       
                              
                            if(steamPara.tempr_set >= 80)
                            {
                                if(tempr_box.cur <= (STEAM_PID.u16_itemtemp - 40))
                                    ht_Otop_out.perc = 100;
                                else if(tempr_box.cur <= (STEAM_PID.u16_itemtemp+1))
                                    ht_Otop_out.perc = STEAM_PID.u8_iPriVal/10; 
                                else
                                    ht_Otop_out.perc = 0;
                            }
                            else
                            {
                                if(tempr_box.cur <= STEAM_PID.u16_itemtemp)
                                    ht_Otop_out.perc = STEAM_PID.u8_iPriVal/10; 
                                else
                                    ht_Otop_out.perc = 0;
                            }                            
                        }                                                                           
                    }                       
                }
                else
                {
                    if(gb_skeeptemper == 0)
                    {
                        if((tempr_box.cur > 85)&& (tempr_box.cur <= pretemper+1))
                        {
                            if(system_sec_f)
                                keepcnt++;
                            if(keepcnt >= 300)
                            {
                                keepcnt = 0;
                                gb_hlevel = 1;
                                gb_skeeptemper = 1;
                            }
                        }
                        else
                        {
                            gb_hlevel = 0;
                            keepcnt = 0;
                            pretemper = tempr_box.cur;
                        }
                    }  
                    else
                    {
                        keepcnt = 0;
                        pretemper = 85;
                    }                    
                    if(gb_skeeptemper == 0)
                    {                                    
                        if(tempr_box.cur >= 90)
                        {
                            changcnt++;
                            if(changcnt >= 30)
                            {
                                gb_skeeptemper = 1;
                            }
                        }                                                    
                    }
                    if(gb_skeeptemper == 0)
                    {
                        if(gu8_steamDlyCnt == 0)
                            ht_Ibom_out.perc = 100;
                        else 
                            ht_Ibom_out.perc = 0;	
                        ht_Itop_out.perc = 100;
                        ht_Otop_out.perc = 100;   
                        gu8_smbtmheat = 100;
                        gu8_BakeDlyCnt = 3; 
                        worktimecnt = 0;  
                        cg_heat_f = 0;               
                    }	
                    else
                    {

                        if(tempr_box.cur < (STEAM_PID.u16_itemtemp-2))	//tempr_bom.cur < (STEAM_PID.u16_itemtemp)
                            power = 20; 	
                        else	
                            power = 50;
                        if(tempr_bom.cur < 85)
                        {	
                            power = 50;												
                        }                          
                        if((gu16_allpowercnt < power)&&(gu16_allpowercnt))
                        {
                            if(cg_heat_f == 0)
                            {
                                ht_Itop_out.perc = 100;
                                ht_Ibom_out.perc = 0;
                            }
                            else
                            {
                                ht_Ibom_out.perc = 100;
                                ht_Itop_out.perc = 0;
                            }
                                
                        }
                        else
                        {
                            ht_Itop_out.perc = 0;
                            ht_Ibom_out.perc = 0;
                        }

                        if(STEAM_PID.fitemFlag == 0)
                        {
                            ht_Otop_out.perc = 100;
                        }                            
                        else
                        {     
							if(steamPara.tempr_set >= 115)
                            {
                                powerlow = 35;//30;
                                power = 70;//70;
                            }								
							else if(steamPara.tempr_set >= 110)
                            {
                                powerlow = 25;
                                power = 55;
                            }
								                                
							else if(steamPara.tempr_set >= 105)
                            {
                                power = 45;
                                powerlow = 20;
                            }								
							else
                            {
                                powerlow = 10;
                                power = 35;
                            }
									  
                            if(STEAM_PID.u8_iPriVal > power)
                                STEAM_PID.u8_iPriVal = power;    
                            if(STEAM_PID.u8_iPriVal < powerlow)
                                STEAM_PID.u8_iPriVal = powerlow;                                     
                            ht_Otop_out.perc = STEAM_PID.u8_iPriVal;
                        }                            
                        gu8_smbtmheat = 0;                                              							
                    
                    }
                    if(gu8_AddWaterTime1)
                    {
                        ht_Ibom_out.perc = 0;
                        ht_Itop_out.perc = 0;
                        gu8_smbtmheat = 0;
                    }                      
                } 
                //温度过高，蒸盘关闭工作
                if(tempr_bom.cur > 140)
                {
                    ht_Itop_out.perc = 0;
                    ht_Ibom_out.perc = 0;
                }           
            }
            break;
            case WORK_THAW:			     // 发酵模式7	
            case WORK_FAJIAO:
            {
                if(gu8_AddWaterTime1)
                {
                    gu8_smbtmheat = 0;
                    ht_Itop_out.perc = 0;
                    ht_Ibom_out.perc = 0;                    
                    // if(gb_TemptrDown)
                    // {
                    //     ht_Itop_out.perc = 100;
                    //     ht_Ibom_out.perc = 0;
                    // }                    
                }
                else
                {                    
                    gb_skeeptemper = 1;
                    {   
                        if(steamPara.tempr_set <= 55)     
                        {
                            if(tempr_box.cur >= STEAM_PID.u16_itemtemp-15)
                            {
                                if(STEAM_PID.u8_iPriVal > 50)
                                    ht_Itop_out.perc = 50;
                                else
                                    ht_Itop_out.perc = STEAM_PID.u8_iPriVal;
                            }
                            else
                                ht_Itop_out.perc = STEAM_PID.u8_iPriVal;
                        }   
                        else               
                            ht_Itop_out.perc = STEAM_PID.u8_iPriVal;
                        ht_Ibom_out.perc = 0;   
                        gu8_smbtmheat = 0;                           
                    }                        
                    if(tempr_box.cur <= STEAM_PID.u16_itemtemp)
                        ht_Otop_out.perc = STEAM_PID.u8_iPriVal/6;     
                    else
                        ht_Otop_out.perc = 0;                      
                }
                //温度过高，蒸盘关闭工作
                if(tempr_bom.cur > 140)
                {
                    ht_Itop_out.perc = 0;
                    ht_Ibom_out.perc = 0;
                }                 
            }
            break;
            case WORK_SOFT:
            {
				if(door.sta == DOOR_OPEN)
				{
					boxlock_f = 0;
				}
				gb_skeeptemper = 1;
                if(presoft_step != steamPara.soft_step)
                {
                    worktime = 0;
                    cyc_cnt = 0;
                    if(steamPara.soft_step == 2)
                        gu8_AddWaterTime1 = 80;
                }
                if(steamPara.soft_step == 2)
                {                    
                    if(system_sec_f)
                        u16_up(&worktime);
                    if(worktime == 156)
                    {
                        gu8_draintime = 30;
                    }
                    else if(worktime == 186)
                    {
                        if(cyc_cnt < 9)
                        {                        
                            worktime = 0;                        
                            cyc_cnt++;
                            gu8_AddWaterTime1 = 80;
                            gu8_draintime = 0;
                        }
                    }
                    
                }
                else if(steamPara.soft_step == 4)
                {
                    if(system_sec_f)
                        u16_up(&worktime);
                    if(worktime <= 80)
                    {
                        gu8_draintime = 30;//30秒
                        gu8_AddWaterTime1 = 80;//8秒                        
                    }
                    else if(worktime <= 110)
                    {
                        gu8_draintime = 30;
                        gu8_AddWaterTime1 = 0;
                    }
                    else
                    {
                        gu8_draintime = 0;
                        gu8_AddWaterTime1 = 0;                        
                    }
                }
                else
                {
                    cyc_cnt = 0;
                    worktime = 0;
                    gu8_draintime = 0;
                    gu8_AddWaterTime1 = 0;                       
                }                
                presoft_step = steamPara.soft_step;
            }
            break;
            case WORK_CHUJUN:
            {
                	
                if(system_sec_f)
                    steamPara.time_sec++;
                if(steamPara.time_sec >= 60)
                {
                    steamPara.time_sec = 0;
                    u8_up(&steamPara.time_min);
                }

                if(gu8_DisinfWorkStatus == 1)
                { 
                    gb_skeeptemper = 1;            
                    if(gu8_AddWaterTime1)
                    {
						ht_Itop_out.perc = 0;
                        ht_Ibom_out.perc = 0;                        
                    }
                    else
                    {
                        if(steamPara.time_min < 4)		
                        {
                            ht_Itop_out.perc = 100;
                        }	
                        else
                        {
                            
                            if(tempr_box.cur < STEAM_PID.u16_itemtemp)	
                                ht_Itop_out.perc = 20; 	
                            else	
                                ht_Itop_out.perc = 50;   
                                                     
                        }	
                        ht_Ibom_out.perc = 0; 	
                        gu8_smbtmheat = 0;											
                    }
                    if(STEAM_PID.fitemFlag == 0)	
                    {
                        ht_Otop_out.perc = 100;	
                    }					 
                    else
                    {
                        if(STEAM_PID.u8_iPriVal > 70)
                            STEAM_PID.u8_iPriVal = 70;     
                        if(STEAM_PID.u8_iPriVal < 35) 
                            STEAM_PID.u8_iPriVal = 35;                                 
                        ht_Otop_out.perc = STEAM_PID.u8_iPriVal;                                               
                    } 
                    if(steamPara.time_min >= 5)   
                    {
                        gu8_DisinfWorkStatus = 2;
                        gb_WaterProcess = 0;
                    }    
                }
                else if(gu8_DisinfWorkStatus == 2)	
                {
                    gb_skeeptemper = 1;
                    if(STEAM_PID.fitemFlag == 0)	
                    {
                        ht_Otop_out.perc = 100;                        
                    }					 
                    else
                    {
                        if(STEAM_PID.u8_iPriVal > 70)
                            STEAM_PID.u8_iPriVal = 70;   
                        if(STEAM_PID.u8_iPriVal < 35) 
                            STEAM_PID.u8_iPriVal = 35;     
                        ht_Otop_out.perc = STEAM_PID.u8_iPriVal;                                               
                    }  
                    ht_Ibom_out.perc = 0;
                    ht_Itop_out.perc = 0;      
                    gu8_smbtmheat = 0;               
                }  
                //温度过高，蒸盘关闭工作
                if(tempr_bom.cur > 140)
                {
                    ht_Itop_out.perc = 0;
                    ht_Ibom_out.perc = 0;
                }                           
            }
            break;
            case WORK_DESCAL:
            {
				gb_skeeptemper = 1;
                if(system_sec_f)
                    u16_up(&worktime);
                if(dscal_heat_f)
                {
                    if(tempr_bom.cur >= 80)
                        dscal_heat_f = 0;
                }
                else
                {
                    if(tempr_bom.cur <= 70)
                        dscal_heat_f = 1;                    
                }
                if(worktime >= 15*60)
                {
                    worktime = 0;
                    cyc_cnt++;
                    if(cyc_cnt < 4)
                    {
                        gu8_AddWaterTime1 = 80;
                        gu8_draintime = 0;                        
                    }
                }
                if(cyc_cnt < 4)
                {
                    if(worktime >= (15*60-30))
                    {
                        gu8_draintime = 30;
                        gu8_AddWaterTime1 = 0;
                        ht_Ibom_out.perc = 0; 	
                        ht_Itop_out.perc = 0;	
                                            
                    }
                    else
                    {
                        if(gu8_AddWaterTime1)
                        {
                            ht_Ibom_out.perc = 0; 	
                            ht_Itop_out.perc = 0;	
                                                        
                        }
                        else
                        {
                            if(dscal_heat_f)
                            {
                                if(gu16_allpowercnt < 50)
                                {
                                    ht_Ibom_out.perc = 100;
                                    ht_Itop_out.perc = 0;
                                } 	
                                else
                                {
                                    ht_Itop_out.perc = 100; 
                                    ht_Ibom_out.perc = 0;  
                                }                             
                            }
                            else
                            {
                                ht_Ibom_out.perc = 0; 	
                                ht_Itop_out.perc = 0;                                 
                            }
                        }
                    }
                }
                else
                {
                    gu8_AddWaterTime1 = 0;
                    gu8_draintime = 0;    
                    ht_Ibom_out.perc = 0; 	
                    ht_Itop_out.perc = 0;  	                                        
                }
            }
            break;
            default:
                break;
        }    //
	
    }
    else
    {
        clear_steam(); 
        if(steamCtrl.state != STA_PAUSE)
        {
            gb_washboxwork = 0;
            gb_skeeptemper = 0;
            worktimecnt = 0;
            presoft_step = 0;
			gb_washboxwork = 0;
            
        } 
        else
        {
            if((tempr_box.cur <= (STEAM_PID.u16_itemtemp-2))&&(steamPara.menu != WORK_SOFT))
                worktimecnt = 0;
        }		
        changcnt = 0;
        work_dly = 0;
        gb_hlevel = 0;
        keepcnt = 0;
        pretemper = 0;
        cg_dly = 0;
        cg_heat_f = 0;
        power = 0;

        gu8_smbtmheat = 0;        
    }   
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void bakepower_allot(void)
{
    static u16 changcnt = 0;

    if((gu8_SystemBeginTime > 2))
        return; 
    if(bakeCtrl.state == STA_WORK)
        klock = 1;
    else
        klock = 0;
    if(gb_stubecheck ||gb_btubecheck)
    {
        if(gb_btchekdly||(gb_btubecheck == 0))
            clear_bake();
        return;
    }
    if(gs_tofaceBTubeError)
    {
        clear_bake();
        klock = 0;
        changcnt = 0;
        return;
    }    
    if(bakeCtrl.state == STA_WORK)
    {//工作状态       
        switch(bakePara.menu)
        {
            case BWORK_MEAT:  
            case BWORK_FISH:              
            case BWORK_STEAK:         	  
            case BWORK_PIZZA:			  
            case BWORK_CAKE:              
            case BWORK_TUBERS:             
            case BWORK_NUT:   
            case BWORK_KEEPWARM:            
            case BWORK_CHUJUN:                       
            { 
                cycle_f = 1; 
                cold_f = 1;

                //100度10%
                if((((steamCtrl.state == STA_WORK)&&gb_skeeptemper)||(steamCtrl.state != STA_WORK))&&(gu8_BakeDlyCnt == 0))
                {
                    if(gb_twoboxwork == 0)
                    {
                        if(bakePara.tempr_set <= 60)
                        {
                            if(BAKE_PID.u8_iPriVal >= 50)
                                ht_Lbom_out.perc = 50;
                            else
                                ht_Lbom_out.perc = BAKE_PID.u8_iPriVal;
                        }   
                        else if(bakePara.tempr_set <= 90) 
                        {
                            if(BAKE_PID.u8_iPriVal >= 80)
                                ht_Lbom_out.perc = 80;
                            else
                                ht_Lbom_out.perc = BAKE_PID.u8_iPriVal;                        
                        } 
                        else if(bakePara.tempr_set <= 140)
                        {
                            if(tempr_top.cur >= (BAKE_PID.u16_itemtemp-60))
                            {
                                if(BAKE_PID.u8_iPriVal >= 80)
                                    ht_Lbom_out.perc = 80;
                                else
                                    ht_Lbom_out.perc = BAKE_PID.u8_iPriVal;                            
                            }
                            else
                                ht_Lbom_out.perc = BAKE_PID.u8_iPriVal;
                        }   
                        else           
                            ht_Lbom_out.perc = BAKE_PID.u8_iPriVal;
                        gu8_bktopheat = ht_Lbom_out.perc;
                    }
                    else
                    {
                        if(bakePara.tempr_set <= 60)
                        {
                            if(BAKE_PID.u8_iPriVal >= 50)
                                gu8_bktopheat = 50;
                            else
                                gu8_bktopheat = BAKE_PID.u8_iPriVal;
                        }   
                        else if(bakePara.tempr_set <= 90) 
                        {
                            if(BAKE_PID.u8_iPriVal >= 80)
                                gu8_bktopheat = 80;
                            else
                                gu8_bktopheat = BAKE_PID.u8_iPriVal;                        
                        } 
                        else if(bakePara.tempr_set <= 140)
                        {
                            if(tempr_top.cur >= (BAKE_PID.u16_itemtemp-60))
                            {
                                if(BAKE_PID.u8_iPriVal >= 80)
                                    gu8_bktopheat = 80;
                                else
                                   gu8_bktopheat = BAKE_PID.u8_iPriVal;                            
                            }
                            else
                                gu8_bktopheat = BAKE_PID.u8_iPriVal;
                        }   
                        else           
                            gu8_bktopheat = BAKE_PID.u8_iPriVal; 
                        if((gu16_allpowercnt > gu8_smbtmheat)&&(gu16_allpowercnt < (gu8_smbtmheat+gu8_bktopheat))&&(gu16_allpowercnt < 99))
                        {
                            ht_Lbom_out.perc = 100;
                        }    
                        else
                            ht_Lbom_out.perc = 0;                   
                    }

                }                    
                else
                    ht_Lbom_out.perc = 0;

                if(ht_Lbom_out.perc)
                    gu8_steamDlyCnt = 3;                      			
            }                                
            break;
            default:
                break;
        }    //
    }
    else
    {
        clear_bake();
        if(bakeCtrl.state != STA_PAUSE)//暂停工作，风机是否关闭
        {
            cycle_f = 0;
            cold_f = 0;
        } 		
        changcnt = 0;
        gu8_bktopheat = 0;
    }

    
}
void two_work_check(void)
{
    if((steamCtrl.state == STA_WORK)&&(bakeCtrl.state == STA_WORK))
    {
        gb_twoboxwork = 1;
    }
    else
    {
        gb_twoboxwork = 0;
    }
    if(system_600ms_f)
    {
        if((steamCtrl.state == STA_WORK)||(bakeCtrl.state == STA_WORK))
        {
            if (gu16_allpowercnt < 99)
                gu16_allpowercnt++;
            else
            {
                gu16_allpowercnt = 0;
                cg_heat_f = !cg_heat_f;
            }
        }
        else
            gu16_allpowercnt = 0;
    }    
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void steam_ctrl(void)
{
//	static bool gb_work = 0;		
    if(system_100ms_f)
    {
        u8_dn(&gu8_BakeDlyCnt);     
        u8_dn(&gu8_steamDlyCnt); 
        CheckAddWaterone();
        CheckAddWater2();
        two_work_check();
        steampower_allot();
        bakepower_allot();     
    }
	
    if(system_sec_f)
    {
        steamtemper_change();
	    PID_Operation(&STEAM_PID,tempr_box.cur);
        PID_Operation(&BAKE_PID,tempr_top.cur);
        if((steamCtrl.state != STA_PAUSE))
            u8_dn(&gu8_draintime);
        //Load_test();
    }       
}
/***************************************************************************************
* Function Name  : 
* Description    : 
* Input          : 
* Return         : 
* Not            : 
***************************************************************************************/
void Load_test(void)
{

}

